package com.qgs.wcs.controller;

import com.ioserver.bean.Union_DataType;
import com.qgs.wcs.ioserver.IOServerApi;
import com.qgs.wcs.ioserver.IOServerService;
import com.sun.jna.WString;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Vector;

/**
 * @Author: 蔡翔
 * @Date: 2019/10/12 15:15
 * @Version 1.0
 */
@RestController
@RequestMapping("/forIoserverTest2")
public class TestController2 {

    //IOServerService ioServerService = IOServer.INSTANCE.getInstance();
    @Autowired
    IOServerService ioServerService;

    @GetMapping("/getConnection")
    public String getConnection() throws Exception{

        String ip = "127.0.0.1";
        String port = "12380";
        IOServerApi ioServerApi = new IOServerApi();
        Integer result;
        try {
            result = ioServerApi.funcConnect(ip,port);
        }catch (Exception e){
            return e.getMessage();
        }
        if(result == 0){
            return "连接成功";
        }else if(result== -1){
            return "连接失败，但是连通IOServer";
        }else {
            return "异常";
        }
    }

    @GetMapping("/getValueByName")
    public Union_DataType.ByValue aa() throws Exception{
        System.out.println("TestController2"+ioServerService.hashCode());
        return ioServerService.getValueByName("Tag1");
    }

    @GetMapping("/getBatchValueByNames")
    public List<Union_DataType.ByValue> getBatch() throws Exception{
        return ioServerService.getBatchValueByNames("Tag1,Tag2");
    }

    @GetMapping("/subscribeAllTags")
    public Vector<WString> subscribeAllTags() throws Exception{
        return ioServerService.getAllTagName();
    }

    @GetMapping("/disConnect")
    public Integer disConnect() throws Exception{
        return ioServerService.funcDisConnect();
    }
}
